<?php

class AccountController extends Controller
{

  protected function loginAction()
  {
    if ($this->request()->method('POST')) {
      try {
        $email = $this->request()->post('email');
        $password = $this->request()->post('password');

        Account::login($email, $password);

        $url = $this->request()->get('redirect', '/admin');

        return $this->response()->redirect($url);
      }
      catch (LoginException $e) {
        s::getInstance()->warnings($e->getMessage());

        $this->response()->set('email', $email);
      }
    }
  }

  protected function logoutAction()
  {
    Account::logout();

    return $this->response()->redirect('/admin');
  }

}
